package com.bcurtu.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.support.PagedListHolder;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.bcurtu.db.Account;
import com.bcurtu.service.TempAliasService;


public class LoginController implements Controller {

	private TempAliasService service;


	public TempAliasService getService() {
		return service;
	}

	public void setService(TempAliasService service) {
		this.service = service;
	}

	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String alias = request.getParameter("alias");
		String forward = request.getParameter("forward");
		Account account = this.service.getAccountByAliasAndForward(alias, forward);
		if (account == null) {
			return new ModelAndView("error");
		}
		else {
			request.getSession().setAttribute("userAccount", account);
			String forwardAction = request.getParameter("forwardAction");
			response.sendRedirect(forwardAction);
			return null;
		}
	}

}
